package com.heima.article.feign;

import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
public class ArticleClient implements IArticleClient {

    @Autowired
    private ApArticleService apArticleService;

    @Override
    @PostMapping("/api/v1/article/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    @GetMapping("/api/v1/article/select/{id}")
    public ResponseResult<ApArticle> select(@PathVariable("id")  Long id) {
        ApArticle apArticle = apArticleService.getById(id);
        if (apArticle != null) {
            return ResponseResult.okResult(apArticle);
        } else {
            return ResponseResult.errorResult(AppHttpCodeEnum.OPERATE_ERROR,"ap_article表查询结果为空！");
        }
    }

    @PostMapping("api/v1/article/batchSelect")
    public ResponseResult<List<String>> batchSelect(@RequestBody List<Long> ids){
        List<String> names =  apArticleService.batchSelect(ids);
        return ResponseResult.okResult(names);
    }

}
